package com.photoeditor.demo.util.gallery.common;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.common.base.ComponentContext;
import com.photoeditor.R;


/**
 * 缓存一些Bitmap
 */
public class LoadThumbnailUtil {
	/**
	 * 默认的底图
	 */
	private Bitmap mDefaultBitmap;
	
	/**
	 * 选中状态的图片
	 */
	private Bitmap mDefaultSelectedBitmap;
	
	/**
	 * 未选中状态的图片
	 */
	private Bitmap mDefaultUnSelectedBitmap;
	
	/**
	 * checkBox选中状态的图片
	 */
	private Bitmap mCheckBoxSelectedBitmap;
	
	/**
	 * checkBox未选中状态的图片
	 */
	private Bitmap mCheckBoxUnSelectedBitmap;
	
	/**
	 * playVideo未选中状态图片
	 */
	private Bitmap mPlayVideoUnSelectedBitmap;
	
	/**
	 * playVideo选中状态图片
	 */
	private Bitmap mPlayVideoSelectedBitmap;

	/**
	 * Gif Sign
	 */
	private Bitmap mGIFSignBitmap;

	/**
	 * Dynamic sign
	 */
	private Bitmap mDynamicVideoSignBitmap;

	
	private static LoadThumbnailUtil mInstance;
	
	private LoadThumbnailUtil(){
	}
	
	public static LoadThumbnailUtil getInstance(){
		if(mInstance == null){
			mInstance = new LoadThumbnailUtil();
		}
		return mInstance;
	}
	
	/**
	 * 获取底图
	 * @return
	 */
	public Bitmap getDefaultBitmap(){
		if(mDefaultBitmap == null || mDefaultBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mDefaultBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_default_image);
		}
		return mDefaultBitmap;
	}
	
	/**
	 * 获取选中状态的图
	 * @return
	 */
	public Bitmap getDefaultSelectedBitmap(){
		if(mDefaultSelectedBitmap == null || mDefaultSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mDefaultSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_choose_on);
		}
		return mDefaultSelectedBitmap;
	}
	
	/**
	 * 获取未选中状态的图
	 * @return
	 */
	public Bitmap getDefaultUnSelectedBitmap(){
		if(mDefaultUnSelectedBitmap == null || mDefaultUnSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mDefaultUnSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_choose_off);
		}
		return mDefaultUnSelectedBitmap;
	}
	
	/**
	 * 获取checkbox选中状态的图
	 * @return
	 */
	public Bitmap getCheckBoxSelectedBitmap(){
		if(mCheckBoxSelectedBitmap == null || mCheckBoxSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mCheckBoxSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_choose_on);
		}
		return mCheckBoxSelectedBitmap;
	}
	
	/**
	 * 获取checkbox未选中状态的图
	 * @return
	 */
	public Bitmap getCheckBoxUnSelectedBitmap(){
		if(mCheckBoxUnSelectedBitmap == null || mCheckBoxUnSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mCheckBoxUnSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_choose_off);
		}
		return mCheckBoxUnSelectedBitmap;
	}
	
	/**
	 * 获取playVideo选中状态的图
	 * @return
	 */
	public Bitmap getPlayVideoSelectedBitmap(){
		if(mPlayVideoSelectedBitmap == null || mPlayVideoSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mPlayVideoSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_play_video_selected);
		}
		return mPlayVideoSelectedBitmap;
	}
	
	/**
	 * 获取playVideo未选中状态的图
	 * @return
	 */
	public Bitmap getPlayVideoUnSelectedBitmap(){
		if(mPlayVideoUnSelectedBitmap == null || mPlayVideoUnSelectedBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mPlayVideoUnSelectedBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_play_video);
		}
		return mPlayVideoUnSelectedBitmap;
	}

	/**
	 * 获取GIF sign
	 * @return
	 */
	public Bitmap getGIFSignBitmap(){
		if(mGIFSignBitmap == null || mGIFSignBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mGIFSignBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_gif);
		}
		return mGIFSignBitmap;
	}

	/**
	 * 获取GIF sign
	 * @return
	 */
	public Bitmap getDynamicVideoSignBitmap(){
		if(mDynamicVideoSignBitmap == null || mDynamicVideoSignBitmap.isRecycled()){
			Resources res = ComponentContext.getContext().getResources();
			mDynamicVideoSignBitmap = BitmapFactory.decodeResource(res, R.drawable.ic_preview_iocn_play);
		}
		return mDynamicVideoSignBitmap;
	}
	
	/**
	 * 释放内存
	 */
	public void recycle(){
		mDefaultBitmap = null;
		mDefaultSelectedBitmap = null;
		mDefaultUnSelectedBitmap = null;
		mCheckBoxSelectedBitmap = null;
		mCheckBoxUnSelectedBitmap = null;
		mPlayVideoSelectedBitmap = null;
		mPlayVideoUnSelectedBitmap = null;
		mGIFSignBitmap = null;
		mDynamicVideoSignBitmap = null;
	}
}
